package com.aaa.work1226.service.impl;

import com.aaa.work1226.entity.Userinfo;
import com.aaa.work1226.dao.UserinfoMapper;
import com.aaa.work1226.entity.vo.PageParam;
import com.aaa.work1226.service.IUserinfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ql
 * @since 2022-12-26
 */
@Service
public class UserinfoServiceImpl extends ServiceImpl<UserinfoMapper, Userinfo> implements IUserinfoService {

    @Override
    public IPage<Userinfo> selNameAndAge(Userinfo userinfo, PageParam pageParam) {

        QueryWrapper<Userinfo> userinfoQueryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(userinfo.getName())){
            userinfoQueryWrapper.like("name",userinfo.getName());
        }
        if (userinfo.getAge()!=null){
            userinfoQueryWrapper.like("age",userinfo.getAge());
        }
        System.out.println("userinfo = " + userinfo+"---"+pageParam.toString());

        Page<Userinfo> userinfoPage = new Page<>();
        userinfoPage.setCurrent(pageParam.getCurrent());
        userinfoPage.setSize(pageParam.getSize());

        return this.page(userinfoPage,userinfoQueryWrapper);
    }
}
